var $ = require('jquery');
var chatList = require('../chatList');
var editArea = require('../editArea');
var clueInfo = require('../clueInfo');
var recentContacts = require('../recentContacts');
/**
 * 创建聊天窗口
 * @param chatId
 * @param type
 * @param clueType
 * @param info
 * @returns {Content}
 */
module.exports.create = function (chatId, type, clueType, info) {
  var $content =  $('<div class="im-content hide">');
  $content.attr('id', 'chat-' + chatId)
    .attr('data-type', type);
  var recent = recentContacts.create($content);
  var $window = $('<div class="im-chat-window">');
  var list = chatList.create($window);
  var area = editArea.create($window);
  $content.append($window);
  var clue = clueInfo.create($content, clueType, info);
  $content.appendTo('.im-wrap');
  return new Content(chatId, list, area, clue, recent);
};

function Content(chatId, list, editArea, clue, recent) {
  this.chatId = chatId;
  this.chatList = list;
  this.editArea = editArea;
  this.clueInfo = clue;
  this.recentContacts = recent;
}

Content.prototype.active = function () {
  var id = this.chatId;
  $('#chat-' + id).removeClass('hide').siblings('.im-content').addClass('hide');
};

Content.prototype.remove = function () {
  $('#chat-' + this.chatId).remove();
};
